package com.zhs.smartmall.order.service.impl;


import com.zhs.smartmall.order.model.OmsOrder;
import com.zhs.smartmall.order.dao.OmsOrderDao;
import com.zhs.smartmall.order.service.IOmsOrderService;
import com.zhs.smartmall.order.dto.OmsOrderDto;


import com.zhs.smartmallcommon.exception.ServiceException;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhs.smartmallcommon.Enum.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import cn.hutool.core.bean.BeanUtil;
import javax.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;


/**
 *
 * @author zhenghuisheng
 * @since 2023-11-12
 */
@Service
@Slf4j
public class OmsOrderServiceImpl extends ServiceImpl< OmsOrderDao, OmsOrder> implements IOmsOrderService {

    @Resource
    private OmsOrderDao omsOrderDao;

    @Override
    @Transactional
    public R addOrUpdate(OmsOrderDto omsOrderDto) {
        if (BeanUtil.isEmpty(omsOrderDto)) throw new ServiceException("数据不能为空");
        OmsOrder omsOrder = new OmsOrder();
        BeanUtil.copyProperties(omsOrderDto,omsOrder);
        if (omsOrderDto.getId() == null){
            omsOrderDao.insert(omsOrder);
            return R.ok("数据插入成功");
        }else {
            omsOrderDao.updateById(omsOrder);
            return R.ok("数据更新成功");
        }
    }
}